class Solution {
public static boolean wordPattern(String pattern, String str) {
        String[] string = str.split(" ");
        if(pattern.length() != string.length) return false;
        HashMap<Character,String> map = new HashMap<>();
        for(int i=0;i<pattern.length();i++)
        {
            char tmp=pattern.charAt(i);
            if(map.containsKey(tmp))
            {
                if(!map.get(tmp).equals(string[i]))
                return false;
            }
            else{
                if(map.containsValue(string[i]))
                return false;
                map.put(tmp,string[i]);
            }
        }
        return true;
    }
}

